package com.zsrt.day20170424.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import org.junit.Test;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;

/**
*@author jzh
*@创建时间 2017年4月24日下午3:31:44
*类说明：
*/
public class IOTest {
	@Test
	public void test1(){
		File file =new File("iotest/a.txt");
		OutputStreamWriter osw=null;
		try {
			OutputStream os=new FileOutputStream(file);
			osw = new OutputStreamWriter(os);
			osw.write(new String("中深软通123"));
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			if(osw!=null){
				osw.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	public void printDirctories(File file,int level){
		//File file=new File("e:/a");
		String preStr="";
		for(int i=0;i<level;i++){
			preStr+="   ";
		}
		
		File[] files=file.listFiles();
		for(int i=0;i<files.length;i++){
			System.out.println(preStr+files[i].getName());
			if(files[i].isDirectory()){
				printDirctories(files[i], level+1);
			}
		}
	}
	
	@Test
	public void printDirctoriesTest(){
		File file=new File("e:/a");
		System.out.println(file.getName());
		printDirctories(file,1);
	}

}
